use thiserror::Error;

#[derive(Error, Debug)]
pub enum AppError {
    #[error("Database error: {0}")]
    DbErr(#[from] sea_orm::DbErr),

    #[error("DuckDB error: {0}")]
    DuckErr(#[from] duckdb::Error),

    #[error("Migration error: {0}")]
    MigrateErr(String), // Placeholder, sea_orm_migration::MigrateErr is not directly used here

    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),

    #[error("Initialization error: {0}")]
    InitError(String),

    #[error("Custom error: {0}")]
    Custom(String),

    #[error("Route not found: {0}")]
    NotFound(String),

    #[error("Invalid payload for route: {0}")]
    InvalidPayload(String),

    #[error("Serialization error: {0}")]
    Serialization(String),
}

// 为 tauri::Error 实现 From<AppError> 以便在 tauri commands 中使用
impl From<AppError> for tauri::Error {
    fn from(error: AppError) -> Self {
        error.into()
    }
}

pub type Result<T, E = AppError> = std::result::Result<T, E>;
